angular.module('password-match-directive', []).directive('passwordMatch', function() {
	return {
        restrict : 'A',
        scope : true,
        require : 'ngModel',
        link : function (scope, elem , attrs, ctrl) {
            var checker = function () {
                var comfirmPassword = scope.$eval(attrs.ngModel); 
                var password = scope.$eval(attrs.passwordMatch);
                return password == comfirmPassword;
            };
            scope.$watch(checker, function (n) {
            	ctrl.$setValidity("matched", n);
            });
        }
    };
});